package com.hlingsoft.kkh.action.admin;


import cn.jpush.api.utils.StringUtils;
import com.hlingsoft.kkh.dao.ReplyDao;
import com.hlingsoft.kkh.entity.*;
import com.hlingsoft.kkh.entity.vo.JsonVo;
import com.hlingsoft.kkh.entity.vo.PageVo;
import com.hlingsoft.kkh.util.Common;
import com.hlingsoft.kkh.util.HttpUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * Created by selbylei on 2015/6/23.
 */
@Controller
@RequestMapping("admin/report")
public class AdminReportAction extends AdminBaseAction {


    /**
     * 列表页
     * @param pageNum
     * @param modelMap
     * @return
     */
    @RequestMapping(value = "/list.htm")
    public String list(
            HttpServletRequest request,
            ModelMap modelMap) {
        List<Report> reportList = reportDao.getAllReport();
        modelMap.put("reportList", reportList);
        return "system/report/list";
    }


    @RequestMapping(value = "/userOff.json")
    @ResponseBody
    public JsonVo<String> add(
            @RequestParam(value = "appUserId") Integer appUserId,
            ModelMap modelMap) {
        JsonVo<String> json = new JsonVo<String>();
        try {

            Date now = new Date();
            json.setResult(true);
            //删除用户
            AppUser user = userDao.getUserById(appUserId);
            user.setAvailable(0);
            userDao.updateUser(user);

            //删除用户活动
            List<Events> eventsList = eventsDao.getAllEventsByAppUserId(appUserId);
            for (Events events:eventsList){
                events.setAvailable(0);
                eventsDao.updateEvents(events);
            }

            //删除跟帖
            List<EventComments> eventCommentsList = eventCommentsDao.getCommentsListByAppUserId(appUserId);
            for (EventComments eventComments:eventCommentsList){
                eventComments.setAvailable(0);
                eventCommentsDao.updateEventComments(eventComments);
            }


            //删除关注
            List<Focus> focusList =focusDao.getFocusByAppUserId(appUserId);
            for (Focus focus:focusList){
                focus.setAvailable(0);
                focusDao.updateFocus(focus);
            }

            //删除点赞
            List<Likes> likesList=likesDao.getAllLikesByAppUserId(appUserId);
            for (Likes likes:likesList){
                likes.setAvailable(0);
                likesDao.updateLikes(likes);
            }

            //删除分享
            List<Share> shareList = shareDao.getShareByAppUserId(appUserId);
            for (Share share : shareList) {
                share.setAvailable(0);
                shareDao.updateShare(share);
            }


            //删除图片
            List<Image> imageList = imageDao.getImageByAppUserId(appUserId);
            for (Image image : imageList) {
                image.setAvailable(0);
                imageDao.updateImage(image);
            }

            //删除收藏
            List<Collect> collectList = collectDao.getByAppUserId(appUserId,0,100);
            for (Collect collect:collectList){
                collect.setAvailable(0);
                collectDao.updateCollect(collect);
            }

            //删除通知
            List<Notification> notificationList = notificationDao.getNotificationByAppUserId(appUserId);
            for (Notification notification:notificationList){
                notification.setAvailable(0);
                notificationDao.updateNotification(notification);
            }
            return json;
        } catch (Exception e) {
            e.printStackTrace();
            json.setMsg("输入参数有误");
            json.setResult(false);
            return json;
        }
    }


}
